package com.bot.service.factory;

import com.bot.service.DashScopeService;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.rag.content.retriever.ContentRetriever;
import dev.langchain4j.service.AiServices;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DashScopeServiceFactory {
    @Resource
    private ChatModel qwenChatModel;
    @Resource
    private ContentRetriever contentRetriever;
    @Resource
    private StreamingChatModel qwenStreamingChatModel;

    @Bean
    public DashScopeService dashScopeService(){
        //会话记忆
        ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(20);
        return AiServices.builder(DashScopeService.class)
                .chatModel(qwenChatModel)
                .chatMemory(chatMemory)  //会话记忆
                //TODO 识别不同的聊天对象
                //TODO 可能要将缓存命中关掉
                .moderationModel(null)  //  是这个吗？ 不确定  得看看
                .chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(20))  //多人独立开辟记忆空间
                .contentRetriever(contentRetriever) //RAG检索增强生成
                .streamingChatModel(qwenStreamingChatModel)  //流式输出模型

                .build();

    }

}
